{{define "content"}}
<div class="page-title-box">
    <div class="row align-items-center">
        <div class="col-auto">
            <h2 class="page-title">用户设置</h2>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-12">
        <form id="user" class="card" method="post" enctype="multipart/form-data">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-2">
                            <label class="form-label">昵称</label>
                            <input name="nickname" type="text" class="form-control" placeholder="请输入昵称"
                                value="{{.User.NickName}}" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-2">
                            <label class="form-label">邮箱</label>
                            <input name="email" type="text" class="form-control" placeholder="请输入邮箱"
                                value="{{.User.Email}}" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-2">
                            <label class="form-label">手机号</label>
                            <input name="mobile" type="text" class="form-control" placeholder="请输入手机号"
                                value="{{.User.Mobile}}" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-2">
                            <label class="form-label">头像</label>
                            <span class="avatar avatar-xl mb-2 mt-2" style="background-image: url({{.User.Avatar}})"></span>
                            <div class="form-file">
                                <input type="file" class="form-file-input" id="avatar" name="avatar">
                                <label class="form-file-label" for="avatar">
                                    <span class="form-file-text" id="file_name">请选择文件...</span>
                                    <span class="form-file-button">预览</span>
                                  </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-footer text-right">
                <input name="id" type="hidden" value="{{.User.ID}}">
                <button type="submit" class="btn btn-primary">提交</button>
            </div>
        </form>
    </div>
</div>
{{end}}
{{define "script"}}
<script type="text/javascript">
    $(document).ready(function () {
        $("#user").on("submit", function (event) {
            $('#user').ajaxSubmit({
                url: "/user/update",
                dataType: "json",
                contentType : false,
                processData : false,
                timeout: 60000,
                success: function (data) {
                    if (data.code == 200) {
                        alert("更新成功!")
                        window.location.href = "/user/list";
                    } else {
                        alert(data.message);
                    }
                }
            })
            return false;
        });
        $("#avatar").on("change", function(event) {
            console.log($("#avatar").val())
            $("#file_name").text($("#avatar").val());
        })
    });
</script>
{{end}}